# -*- coding: utf-8 -*-
from matplotlib import pyplot as plt
from torchvision.transforms import (RandomHorizontalFlip,
                                    RandomVerticalFlip,
                                    RandomCrop,
                                    Resize,
                                    RandomRotation,
                                    transforms)
from PIL import Image


img = Image.open("./a.jpg")
width, height = img.size  # 本例中为 (375, 500)
# 尺寸调整

# 动态设置裁剪尺寸（不超过原图）
crop_size = (min(600, width), min(600, height))

plt.imshow(img)
plt.show()
#几何增强
#3.1随机水平翻转
HF = RandomHorizontalFlip(p=0.8)
hf_img = HF(img)
plt.imshow(hf_img)
plt.show()
#3.2 垂直上下翻转
transforms_VF = RandomVerticalFlip(p = 0.5)
dog_VF = transforms_VF(img)
plt.imshow(dog_VF)
plt.show()
# 随机裁剪：宽高要小于原始图像的宽高
transforms_RC=RandomCrop(size=(224,224))
dog_RC = transforms_RC(img)
plt.imshow(dog_RC)
plt.show()
# 颜色调整
transforms_color =transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.5, hue=0.2)
dog_color = transforms_color(img)
plt.imshow(dog_color)


transforms_RS=Resize(crop_size)
dog_RS = transforms_RS(img)
plt.imshow(dog_RS)
plt.show()

#将几种方法组合在一起
transform = transforms.Compose([transforms_RS,transforms_VF,transforms_RC,transforms_RS])
new_data = transform(img)
plt.imshow(new_data)
plt.show()







